package com.ocom.payconfig.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.card.EntityXfMerchPayInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payconfig.dao.IDaoXfMerchPayInfo;
import com.ocom.payconfig.service.XfMerchPayInfoService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class XfMerchPayInfoServiceImpl extends ServiceImpl<IDaoXfMerchPayInfo, EntityXfMerchPayInfo> implements XfMerchPayInfoService {

	@Override
	@DataSourceAspect(type = DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.SLAVE)
	public EntityXfMerchPayInfo getPayInfo(Long companyId,EntityXfMerchPayInfo entityXfMerchPayInfo) {
		QueryWrapper<EntityXfMerchPayInfo> queryWrapper= Wrappers.query();
		queryWrapper.eq("com_id",entityXfMerchPayInfo.getComId());
		queryWrapper.eq("merch_id",entityXfMerchPayInfo.getMerchId());
		return this.getOne(queryWrapper);
	}

	@Override
	@DataSourceAspect(type = DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.SLAVE)
	public EntityXfMerchPayInfo getPayInfo(Long companyId, Integer merchId) {
		QueryWrapper<EntityXfMerchPayInfo> queryWrapper= Wrappers.query();
		queryWrapper.eq("com_id",companyId);
		queryWrapper.eq("merch_id",merchId);
		return this.getOne(queryWrapper);
	}


	@Override
	@DataSourceAspect(type = DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.MASTER)
	public EntityXfMerchPayInfo addPayInfo(Long companyId,EntityXfMerchPayInfo entityXfMerchPayInfo) {
		Boolean b = this.save(entityXfMerchPayInfo);
		if(!b) return null ;
		return entityXfMerchPayInfo;
	}


	@Override
	@DataSourceAspect(type = DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.MASTER)
	public Boolean delPayInfo(Long companyId,EntityXfMerchPayInfo entityXfMerchPayInfo) {
		QueryWrapper<EntityXfMerchPayInfo> queryWrapper= Wrappers.query();
		queryWrapper.eq("com_id",entityXfMerchPayInfo.getComId());
		queryWrapper.eq("merch_id",entityXfMerchPayInfo.getMerchId());
		return this.remove(queryWrapper);
	}

	@Override
	@DataSourceAspect(type = DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.SLAVE)
	public List<EntityXfMerchPayInfo> getCompanyId(Long companyId) {
		LambdaQueryWrapper<EntityXfMerchPayInfo> queryWrapper= new LambdaQueryWrapper<>();
		queryWrapper.select(EntityXfMerchPayInfo::getMerchId,EntityXfMerchPayInfo::getCompanyId);
		queryWrapper.eq(EntityXfMerchPayInfo::getComId,companyId);
		return this.list(queryWrapper);
	}
}
